import pygame
import sys
import time

# Iniciar pygame
pygame.init()

# Configurar la ventana
ancho = 1024
alto = 768
ventana = pygame.display.set_mode((ancho, alto))
VERDE = [0,200,0]
BLANCO = [255,255,255]
NEGRO = [0,0,0]
ventana.fill(VERDE)
pygame.display.set_caption("Guerra")
pygame.display.update()

character2_1 = pygame.image.load("img/typlosion2.png")
ataquet_2 = pygame.image.load("img/ataquet_2.png")

character_1 = pygame.image.load("img/tyranitar2.png")

character2 = pygame.image.load("img/typlosion.png")
posiciont = pygame.image.load("img/posicion.png")
ataquet = pygame.image.load("img/ataquet.png")
x3,y3 = 20,350

attack1 = (character2,posiciont,ataquet)

character = pygame.image.load("img/tyranitar.png")
ataqueq = pygame.image.load("img/ataqueq.png")
x2,y2 = 750,350



torre = pygame.image.load("img/torre.jpg")
x,y = 0,0


#Pintar fondo en coordenadas (x,y) de la ventana
ventana.blit(torre, [x,y])
ventana.blit(character, [x2,y2])
ventana.blit(character2, [x3,y3])
pygame.display.flip()

#Bucle de eventos
while True:
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			pygame.quit()
			sys.exit()
		if event.type == pygame.KEYDOWN:
			if event.key == pygame.K_LEFT:
				ventana.blit(torre, [x,y])
				ventana.blit(character2, [x3,y3])
				x2 = x2 - 20
				ventana.blit(character, [x2,y2])
				pygame.display.flip()
			if event.key == pygame.K_RIGHT:
				ventana.blit(torre, [x,y])
				ventana.blit(character2, [x3,y3])
				x2 = x2 + 20
				ventana.blit(character_1, [x2,y2])
				pygame.display.flip()
			if event.key == pygame.K_UP:
				ventana.blit(torre, (x,y))
				ventana.blit(character2, (x3,y3))
				y2 = y2 - 20
				ventana.blit(character, (x2,y2))
				pygame.display.flip()
				ventana.blit(torre, (x,y))
				ventana.blit(character2, (x3,y3))
				time.sleep(0.1)
				y2 = y2 + 20
				ventana.blit(character, (x2,y2))
				pygame.display.flip()
			if event.key == pygame.K_DOWN:
			
				for ataqueq in attack2:
					ventana.blit(ataqueq,[x2,y2])
					pygame.display.flip()
					time.sleep(0.1)
					pygame.display.flip()
			
			if event.key == pygame.K_d:
				ventana.blit(torre, [x,y])
				ventana.blit(character, [x2,y2])
				x3 = x3 + 20
				ventana.blit(character2, [x3,y3])
				pygame.display.flip()
			if event.key == pygame.K_a:
				ventana.blit(torre, [x,y])
				ventana.blit(character, [x2,y2])
				x3 = x3 - 20
				ventana.blit(character2_1, [x3,y3])
				pygame.display.flip()
			if event.key == pygame.K_w:
				ventana.blit(torre, (x,y))
				ventana.blit(character, (x2,y2))
				y3 = y3 - 50
				ventana.blit(character2, (x3,y3))
				pygame.display.flip()
				ventana.blit(torre, (x,y))
				ventana.blit(character, (x2,y2))
				time.sleep(0.1)
				y3 = y3 + 50
				ventana.blit(character2, (x3,y3))
				pygame.display.flip()
			if event.key == pygame.K_SPACE:
			
				for ataque in attack1:
					pygame.display.flip()
					ventana.blit(ataquet, [x3,y3])
					pygame.display.flip()
					time.sleep(0.1)
					pygame.display.flip()
